﻿using System;
using System.Collections.Generic;
using System.Linq;
using Sustainalytics.ESGRatings.Computing.Entities;
using Sustainalytics.ESGRatings.Computing.Entities.ESG;
using Sustainalytics.ESGRatings.DataContract;

namespace Sustainalytics.ESGComputing.Service.Tests
{
    internal class TenCompaniesTwoGroupsOneUniverseFakes
    {
        public readonly Guid MatrixId = new Guid("00000000-0000-0000-0000-000000000001");

        public readonly Guid ReferenceUniversesId = new Guid("00000000-0000-0000-0000-000000000002");

        private readonly IList<Guid> _companyIds = new[]
        {
            new Guid("00000000-0000-0000-0000-000000000001"),
            new Guid("00000000-0000-0000-0000-000000000002"),
            new Guid("00000000-0000-0000-0000-000000000003"),
            new Guid("00000000-0000-0000-0000-000000000004"),
            new Guid("00000000-0000-0000-0000-000000000005"),
            new Guid("00000000-0000-0000-0000-000000000006"),
            new Guid("00000000-0000-0000-0000-000000000007"),
            new Guid("00000000-0000-0000-0000-000000000008"),
            new Guid("00000000-0000-0000-0000-000000000009"),
            new Guid("00000000-0000-0000-0000-000000000010"),
        };

        public ESGDataContainer PrepareData()
        {
            var testSet = new ESGDataContainer();
            testSet.IndicatorTemplates = GetIndicatorConfiguration();

            testSet.Companies = GetCorporateData().ToArray();
            testSet.CompaniesScores = GetIndicatorsData();


            var matrixWeights = from weight in GetCompanyWeightsData()
                                select
                                    new CompanyWeights
                                    {
                                        CompanyId = weight.CompanyId,
                                        ProfileHasEsgResearch = weight.ProfileHasEsgResearch,
                                        IndicatorsData = weight.IndicatorsData.Select(x => new Weight(x.Code, x.Value))
                                    };

            testSet.Matrices = new[]
            {
                new WeightMatrix
                {
                    AccountId = Guid.NewGuid(),
                    MatrixId = MatrixId,
                    CompaniesWeights = matrixWeights.ToArray()
                }
            };

            testSet.ReferenceUniverses = new[] { GetReferenceUniverse() };
            return testSet;
        }

        private CompanyWeights[] GetCompanyWeightsData()
        {
            return new[]
            {
                new CompanyWeights  ( _companyIds[0], new[] { new Weight("E.1.1", 0.1f), new Weight("E.1.2", 0), new Weight("E.1.12", 0.15f), new Weight("E.2.2", 0), new Weight("E.1.4", 0), new Weight("G.1.4", 0), new Weight("G.1.1", 0.2f), new Weight("S.1.1", 0.25f), new Weight("S.1.2", 0.3f) },false ),
                new CompanyWeights  ( _companyIds[1], new[] { new Weight( "E.1.1", 0), new Weight( "E.1.2", 0), new Weight( "E.1.12", 0.1f), new Weight( "E.2.2", 0.15f), new Weight( "E.1.4", 0.1f), new Weight( "G.1.4", 0.15f), new Weight( "G.1.1", 0.15f), new Weight( "S.1.1", 0.23f), new Weight( "S.1.2", 0.12f) } ),
                new CompanyWeights  ( _companyIds[2], new[] { new Weight( "E.1.1", 0), new Weight( "E.1.2", 0.05f), new Weight( "E.1.12", 0.1f), new Weight( "E.2.2", 0f), new Weight( "E.1.4", 0.00f), new Weight( "G.1.4", 0.1f), new Weight( "G.1.1", 0.2f), new Weight( "S.1.1", 0.25f), new Weight( "S.1.2", 0.3f) } ),
                new CompanyWeights(_companyIds[3],
                    new[]
                    {
                        new Weight("E.1.1",     0.1f    ),
                        new Weight("E.1.2",     0.15f   ),
                        new Weight("E.1.12",    0f      ),
                        new Weight("E.2.2",     0.2f    ),
                        new Weight("E.1.4",     0f      ),
                        new Weight("G.1.4",     0.2f    ),
                        new Weight("G.1.1",     0f      ),
                        new Weight("S.1.1",     0.35f   ),
                        new Weight("S.1.2",     0f      )
                    }),
              new CompanyWeights(_companyIds[4],
                    new[]
                    {
                        new Weight("E.1.1",   0.2f     ),
                        new Weight("E.1.2",   0.3f     ),
                        new Weight("E.1.12",  0     ),
                        new Weight("E.2.2",   0     ),
                        new Weight("E.1.4",   0     ),
                        new Weight("G.1.4",   0.25f     ),
                        new Weight("G.1.1",   0     ),
                        new Weight("S.1.1",   0     ),
                        new Weight("S.1.2",   0.25f     )
                    }),

            new CompanyWeights(_companyIds[5],
                    new[]
                    {
                        new Weight("E.1.1",   0f    ),
                        new Weight("E.1.2",   0.2f    ),
                        new Weight("E.1.12",  0.2f),
                        new Weight("E.2.2",   0f),
                        new Weight("E.1.4",   0.1f),
                        new Weight("G.1.4",   0f     ),
                        new Weight("G.1.1",   0.15f),
                        new Weight("S.1.1",   0.35f),
                        new Weight("S.1.2",   0f     )
                    }),
new CompanyWeights(_companyIds[6],
                    new[]
                    {
                        new Weight("E.1.1",   0f    ),
                        new Weight("E.1.2",   0f    ),
                        new Weight("E.1.12",  0.3f),
                        new Weight("E.2.2",   0f),
                        new Weight("E.1.4",   0f),
                        new Weight("G.1.4",   0.25f     ),
                        new Weight("G.1.1",   0.25f),
                        new Weight("S.1.1",   0f),
                        new Weight("S.1.2",   0.2f     )
                    }),
new CompanyWeights(_companyIds[7],
                    new[]
                    {
                        new Weight("E.1.1",   0.1f    ),
                        new Weight("E.1.2",   0.1f    ),
                        new Weight("E.1.12",  0f),
                        new Weight("E.2.2",   0f),
                        new Weight("E.1.4",   0.1f),
                        new Weight("G.1.4",   0.25f     ),
                        new Weight("G.1.1",   0.25f),
                        new Weight("S.1.1",   0.1f),
                        new Weight("S.1.2",   0.1f     )
                    }),
new CompanyWeights(_companyIds[8],
                    new[]
                    {
                        new Weight("E.1.1",   0f    ),
                        new Weight("E.1.2",   0f    ),
                        new Weight("E.1.12",  0f),
                        new Weight("E.2.2",   0.15f),
                        new Weight("E.1.4",   0.15f),
                        new Weight("G.1.4",   0.3f     ),
                        new Weight("G.1.1",   0.3f),
                        new Weight("S.1.1",   0.1f),
                        new Weight("S.1.2",   0f     )
                    }),
new CompanyWeights(_companyIds[9],
                    new[]
                    {
                        new Weight("E.1.1",   0f    ),
                        new Weight("E.1.2",   0f    ),
                        new Weight("E.1.12",  0f),
                        new Weight("E.2.2",   0.22f),
                        new Weight("E.1.4",   0.22f),
                        new Weight("G.1.4",   0.2f     ),
                        new Weight("G.1.1",   0.23f),
                        new Weight("S.1.1",   0.05f),
                        new Weight("S.1.2",   0.08f     )
                    }),
            };



        }


        private ICollection<CompanyData> GetCorporateData()
        {
            var companies = new List<CompanyData>
            {
                new CompanyData { Id = _companyIds[0], CompanyType = "Private", TemplateType = "Type A", IndustryGroup = "Diversified Financials", PeerGroup = "Diversified Financials" },
                new CompanyData { Id = _companyIds[1], CompanyType = "Private", TemplateType = "Type B", IndustryGroup = "Diversified Financials", PeerGroup = "Diversified Financials" },
                new CompanyData { Id = _companyIds[2], CompanyType = "Private", TemplateType = "Type B", IndustryGroup = "Diversified Financials", PeerGroup = "Diversified Financials" },
                new CompanyData { Id = _companyIds[3], CompanyType = "Public",  TemplateType = "Type A", IndustryGroup = "Diversified Financials", PeerGroup = "Diversified Financials" },
                new CompanyData { Id = _companyIds[4], CompanyType = "Public",  TemplateType = "Type A", IndustryGroup = "Diversified Financials", PeerGroup = "Diversified Financials" },
                new CompanyData { Id = _companyIds[5], CompanyType = "Public",  TemplateType = "Type A", IndustryGroup = "Diversified Financials", PeerGroup = "Diversified Financials" },
                new CompanyData { Id = _companyIds[6], CompanyType = "Public",  TemplateType = "Type A", IndustryGroup = "Banks", PeerGroup = "Banks" },
                new CompanyData { Id = _companyIds[7], CompanyType = "Public",  TemplateType = "Type A", IndustryGroup = "Banks", PeerGroup = "Banks" },
                new CompanyData { Id = _companyIds[8], CompanyType = "Public",  TemplateType = "Type A", IndustryGroup = "Banks", PeerGroup = "Banks" },
                new CompanyData { Id = _companyIds[9], CompanyType = "Public",  TemplateType = "Type A", IndustryGroup = "Aerospace", PeerGroup = "Aerospace" }

            };
            return companies;
        }

        private IndicatorTemplate[] GetIndicatorConfiguration()
        {
            IndicatorTemplate[] builder =
            {
                new IndicatorTemplate("E.1.1", "E", "P​​"),
                new IndicatorTemplate("E.1.2", "E", "P​​"),
                new IndicatorTemplate("E.1.12", "E", "QLP"),
                new IndicatorTemplate("E.2.2", "E", "QLP"),
                new IndicatorTemplate("E.1.4", "E", "QNP"),
                new IndicatorTemplate("G.1.4", "G", "D"),
                new IndicatorTemplate("G.1.1", "G", "P​​"),
                new IndicatorTemplate("S.1.1", "S", "P​​"),
                new IndicatorTemplate("S.1.2", "S", "QLP")
            };
            return builder;
        }




        private CompanyScores[] GetIndicatorsData()
        {
            return new[]
            {
                new CompanyScores(_companyIds[0], new[] { new IndicatorDefaultScore("E.1.1",100,0f,0f), new IndicatorDefaultScore("E.1.2",0,0f,0f), new IndicatorDefaultScore("E.1.12",50,0f,0f), new IndicatorDefaultScore("E.2.2",20,0f,0f), new IndicatorDefaultScore("E.1.4",0,0f,0f), new IndicatorDefaultScore("G.1.4",90,0f,0f), new IndicatorDefaultScore("G.1.1",50,0f,0f), new IndicatorDefaultScore("S.1.1",20,0f,0f), new IndicatorDefaultScore("S.1.2",30,0f,0f) }) ,
                new CompanyScores(_companyIds[1], new[] { new IndicatorDefaultScore("E.1.1",0,0f,0f), new IndicatorDefaultScore("E.1.2",10,0f,0f), new IndicatorDefaultScore("E.1.12",20,0f,0f), new IndicatorDefaultScore("E.2.2",0,0f,0f), new IndicatorDefaultScore("E.1.4",0,0f,0f), new IndicatorDefaultScore("G.1.4",50,0f,0f), new IndicatorDefaultScore("G.1.1",75,0f,0f), new IndicatorDefaultScore("S.1.1",25,0f,0f), new IndicatorDefaultScore("S.1.2",75,0f,0f) }) ,
                new CompanyScores(_companyIds[2], new[] { new IndicatorDefaultScore("E.1.1",50,0f,0f), new IndicatorDefaultScore("E.1.2",40,0f,0f), new IndicatorDefaultScore("E.1.12",100,0f,0f), new IndicatorDefaultScore("E.2.2",100,0f,0f), new IndicatorDefaultScore("E.1.4",0,0f,0f), new IndicatorDefaultScore("G.1.4",80,0f,0f), new IndicatorDefaultScore("G.1.1",50,0f,0f), new IndicatorDefaultScore("S.1.1",20,0f,0f), new IndicatorDefaultScore("S.1.2",30,0f,0f) }),
                new CompanyScores(_companyIds[3], new[] { new IndicatorDefaultScore("E.1.1",0,0f,0f), new IndicatorDefaultScore("E.1.2",10,0f,0f), new IndicatorDefaultScore("E.1.12",100,0f,0f), new IndicatorDefaultScore("E.2.2",25,0f,0f), new IndicatorDefaultScore("E.1.4",0,0f,0f), new IndicatorDefaultScore("G.1.4",0,0f,0f), new IndicatorDefaultScore("G.1.1",25,0f,0f), new IndicatorDefaultScore("S.1.1",75,0f,0f), new IndicatorDefaultScore("S.1.2",30,0f,0f) }) ,
                new CompanyScores(_companyIds[4], new[] { new IndicatorDefaultScore("E.1.1",25,0f,0f), new IndicatorDefaultScore("E.1.2",25,0f,0f), new IndicatorDefaultScore("E.1.12",25,0f,0f), new IndicatorDefaultScore("E.2.2",25,0f,0f), new IndicatorDefaultScore("E.1.4",35,0f,0f), new IndicatorDefaultScore("G.1.4",35,0f,0f), new IndicatorDefaultScore("G.1.1",25,0f,0f), new IndicatorDefaultScore("S.1.1",99,0f,0f), new IndicatorDefaultScore("S.1.2",0,0f,0f) }) ,
                new CompanyScores(_companyIds[5], new[] { new IndicatorDefaultScore("E.1.1",0,0f,0f), new IndicatorDefaultScore("E.1.2",0,0f,0f), new IndicatorDefaultScore("E.1.12",30,0f,0f), new IndicatorDefaultScore("E.2.2",30,0f,0f), new IndicatorDefaultScore("E.1.4",25,0f,0f), new IndicatorDefaultScore("G.1.4",10,0f,0f), new IndicatorDefaultScore("G.1.1",10,0f,0f), new IndicatorDefaultScore("S.1.1",100,0f,0f), new IndicatorDefaultScore("S.1.2",0,0f,0f) }),
                new CompanyScores(_companyIds[6], new[] { new IndicatorDefaultScore("E.1.1",100,0f,0f), new IndicatorDefaultScore("E.1.2",100,0f,0f), new IndicatorDefaultScore("E.1.12",85,0f,0f), new IndicatorDefaultScore("E.2.2",85,0f,0f), new IndicatorDefaultScore("E.1.4",99,0f,0f), new IndicatorDefaultScore("G.1.4",0,0f,0f), new IndicatorDefaultScore("G.1.1",0,0f,0f), new IndicatorDefaultScore("S.1.1",100,0f,0f), new IndicatorDefaultScore("S.1.2",100,0f,0f) }) ,
                new CompanyScores(_companyIds[7], new[] { new IndicatorDefaultScore("E.1.1",25,0f,0f), new IndicatorDefaultScore("E.1.2",25,0f,0f), new IndicatorDefaultScore("E.1.12",25,0f,0f), new IndicatorDefaultScore("E.2.2",25,0f,0f), new IndicatorDefaultScore("E.1.4",25,0f,0f), new IndicatorDefaultScore("G.1.4",10,0f,0f), new IndicatorDefaultScore("G.1.1",10,0f,0f), new IndicatorDefaultScore("S.1.1",100,0f,0f), new IndicatorDefaultScore("S.1.2",100,0f,0f) }) ,
                new CompanyScores(_companyIds[8], new[] { new IndicatorDefaultScore("E.1.1",0,0f,0f), new IndicatorDefaultScore("E.1.2",0,0f,0f), new IndicatorDefaultScore("E.1.12",30,0f,0f), new IndicatorDefaultScore("E.2.2",30,0f,0f), new IndicatorDefaultScore("E.1.4",0,0f,0f), new IndicatorDefaultScore("G.1.4",100,0f,0f), new IndicatorDefaultScore("G.1.1",100,0f,0f), new IndicatorDefaultScore("S.1.1",80,0f,0f), new IndicatorDefaultScore("S.1.2",80,0f,0f) }),
                new CompanyScores(_companyIds[9], new[] { new IndicatorDefaultScore("E.1.1",10,0f,0f), new IndicatorDefaultScore("E.1.2",10,0f,0f), new IndicatorDefaultScore("E.1.12",10,0f,0f), new IndicatorDefaultScore("E.2.2",25,0f,0f), new IndicatorDefaultScore("E.1.4",10,0f,0f), new IndicatorDefaultScore("G.1.4",50,0f,0f), new IndicatorDefaultScore("G.1.1",50,0f,0f), new IndicatorDefaultScore("S.1.1",0,0f,0f), new IndicatorDefaultScore("S.1.2",100,0f,0f) })
            };
        }



        private ReferenceUniverse GetReferenceUniverse()
        {
            return new ReferenceUniverse
            {
                Id = ReferenceUniversesId,
                Companies = new[]
                {
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704112", CompanyId = _companyIds[0], CompanyName = "Compania1" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704113", CompanyId = _companyIds[1], CompanyName = "Compania2" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704114", CompanyId = _companyIds[2], CompanyName = "Compania3" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704115", CompanyId = _companyIds[3], CompanyName = "Compania4" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704116", CompanyId = _companyIds[4], CompanyName = "Compania5" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704117", CompanyId = _companyIds[5], CompanyName = "Compania6" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704118", CompanyId = _companyIds[6], CompanyName = "Compania7" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ20704119", CompanyId = _companyIds[7], CompanyName = "Compania8" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ207041110", CompanyId = _companyIds[8], CompanyName = "Compania9" },
                    new ReferenceUniverseCompany { CapitalIQID = "IQ207041111", CompanyId = _companyIds[9], CompanyName = "Compania10" },

                }
            };
        }
    }
}